import axios from 'axios'
import {
  ElNotification,
  ElMessageBox,
  ElMessage,
  ElLoading
} from 'element-plus'

axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
// 创建axios实例
const service = axios.create({
  // axios中请求配置有baseURL选项，表示请求URL公共部分
  // baseURL: import.meta.env.VITE_APP_BASE_API,
  baseURL: '/api/wind/',
  
  // 超时
  // timeout: 10000
})

// request拦截器
service.interceptors.request.use(
  config => {
    return config
  },
  error => {
    console.log(error)
    Promise.reject(error)
  }
)

// 响应拦截器
service.interceptors.response.use(
  res => {
    return Promise.resolve(res.data)
  },
  error => {
    // console.log('失败请求', error)
    let { message, response } = error
    let { data } = response

    ElMessage({ message: message, type: 'error', duration: 5 * 1000 })
    return Promise.reject(error)
  }
)

export default service
